package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingPlanDto;
import com.zzyl.entity.NursingPlan;
import com.zzyl.service.NursingPlanService;
import com.zzyl.vo.NursingPlanVo;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static com.zzyl.base.ResponseResult.success;

@RestController
@Slf4j
@RequestMapping("/nursing/plan")
@Api(tags = "护理计划相关接口")
public class NursingPlanController extends BaseController {

    @Autowired
    NursingPlanService nursingPlanService;


    @GetMapping("/search")
    @ApiOperation(value = "护理计划分页查询", notes = "根据名称和状态进行分页查询护理项目信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "项目名称", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "pageNum", value = "页码", dataType = "int", paramType = "query", defaultValue = "1"),
            @ApiImplicitParam(name = "pageSize", value = "每页数量", dataType = "int", paramType = "query", defaultValue = "10"),
            @ApiImplicitParam(name = "status", value = "项目状态", dataType = "int", paramType = "query")
    })
    public ResponseResult pageFind(@RequestParam(value = "name", required = false) String name,
                                   @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                   @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                   @RequestParam(value = "status", required = false) Integer status) {
        log.info("name:{},pageNum:{},pageSize:{},status:{}", name, pageNum, pageSize, status);
        // 调用service查询
        PageResponse<NursingPlanVo> nursingPlanVo = nursingPlanService.pageFind(name, pageNum, pageSize, status);
        return success(nursingPlanVo);
    }

    @GetMapping("/{id}")
    @ApiOperation(value = "根据id查询护理计划", notes = "根据id查询护理计划")
    @ApiImplicitParam(name = "id", value = "护理计划id", dataType = "int", paramType = "path")
    public ResponseResult ById(@PathVariable("id") Integer id) {
        log.info("id:{}", id);
        // 调用service查询
        NursingPlanVo nursingPlanVo = nursingPlanService.ById(id);
        return success(nursingPlanVo);

    }


    @PutMapping("/{id}")
    @ApiOperation(value = "根据id修改护理计划", notes = "根据id修改护理计划")
    public ResponseResult update(@PathVariable("id") Integer id, @RequestBody NursingPlanDto nursingPlanDto) {
        log.info("根据ID修改的内容:id:{},dto:{}", id, nursingPlanDto);
        nursingPlanService.update(nursingPlanDto);
        return success();
    }


    @PostMapping
    @ApiOperation("新增护理计划")
    public ResponseResult addNursingPlan(
            @ApiParam(value = "护理计划数据传输对象", required = true)
            @RequestBody NursingPlanDto nursingPlanDto) {
        nursingPlanService.add(nursingPlanDto);
        return success();
    }

    @DeleteMapping("/{id}")
    @ApiOperation("删除护理计划")
    public ResponseResult deleteNursingPlan(@PathVariable Long id) {
        nursingPlanService.delete(id);
        return success();
    }

    //查询所有护理计划
    @GetMapping
    @ApiOperation("查询所有护理计划")
    public ResponseResult<List<NursingPlan>> getAllNursingPlan() {
        return ResponseResult.success(nursingPlanService.getNursingPlanList());

    }

    //启用禁用
    @PutMapping("/{id}/status/{status}")
    @ApiOperation("启用禁用")
    public ResponseResult updateNursingPlanStatus(@PathVariable("id") Integer id, @PathVariable("status") Integer status) {
        nursingPlanService.updateNursingPlanStatus(id, status);
        return ResponseResult.success();
    }
}